package com.hitqz.robot.biz.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
import com.hitqz.robot.api.business.dto.RobotClientSummaryDto;
import com.hitqz.robot.api.business.dto.TransStaticDateDto;
import com.hitqz.robot.api.business.dto.TransStaticYearDto;
import com.hitqz.robot.api.business.entity.RobotEntity;
import com.hitqz.robot.api.business.entity.RobotWarningRecordEntity;
import com.hitqz.robot.api.business.entity.TicketsEntity;
import com.hitqz.robot.api.business.params.HomeTicketsParams;
import com.hitqz.robot.api.business.params.SortByTypeParams;
import com.hitqz.robot.api.business.vo.*;
import com.hitqz.robot.biz.bean.SseEmitterTopic;
import com.hitqz.robot.biz.config.SseEmitterManager;
import com.hitqz.robot.biz.service.PatrolResultService;
import com.hitqz.robot.biz.service.RobotService;
import com.hitqz.robot.biz.service.RobotWarningRecordService;
import com.hitqz.robot.biz.service.TicketsService;
import com.hitqz.robot.common.core.util.R;
import com.hitqz.robot.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author wengyx
 * @date 2025/04/22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/home/sse")
@Tag(name = "大屏-sse推送")
@Slf4j
public class HomeSseController {

    private final  SseEmitterManager emitterManager;

    @GetMapping("/robot/basicStatus")
    public SseEmitter robotBasicStatus() {
        return emitterManager.addEmitter(SseEmitterTopic.ROBOT_BASIC_STATUS.getTopic(),SecurityUtils.getUser().getId());
    }

    @Scheduled(fixedDelay = 5000L)
    public void sendRobotBasicStatus() {

        emitterManager.sendMessage(SseEmitterTopic.ROBOT_BASIC_STATUS.getTopic(),null);

    }




}
